﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading;
using VNet.VisiSuite.Controls;

namespace VNet.VisiSuite.VisiBoard.Controls
{
    public partial class Header1Control : UserControl
    {
        public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(Header1Control), new FrameworkPropertyMetadata(string.Empty, TitleChangedCallback));
        public static readonly DependencyProperty MenuIconsProperty = DependencyProperty.Register("MenuIcons", typeof(IList<VNetMenuItem>), typeof(Header1Control), new FrameworkPropertyMetadata(null, MenuIconsChangedCallback));

        public Header1Control()
        {
            InitializeComponent();
            _titleTblk.DataContext = _menu.DataContext = this;
            _datetime_text.Text = DateTime.Now.ToString("d-MMM-yyyy h:mm tt");
            var timer = new DispatcherTimer(new TimeSpan(0, 1, 0), DispatcherPriority.Normal, delegate
            {
                _datetime_text.Text = DateTime.Now.ToString("d-MMM-yyyy h:mm tt");
            }, this.Dispatcher);
        }
        public string Title
        {
            get { return (string)GetValue(TitleProperty); }
            set { SetValue(TitleProperty, value); }
        }

        public IList<VNetMenuItem> MenuIcons
        {
            get { return (IList<VNetMenuItem>)GetValue(MenuIconsProperty); }
            set { SetValue(MenuIconsProperty, value); }
        }

        private static void TitleChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = d as Header1Control;
            control._titleTblk.Text = (string)e.NewValue;
        }

        private static void MenuIconsChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var control = d as Header1Control;
            control._menu.Icons = (IList<VNetMenuItem>)e.NewValue;
        }
    }
}
